class DataReader extends Thread{
  private BufferedReader reader;
  private String line;  
  private String NY = "new york";
  private String CHI = "chicago";
  private String LA = "los angeles";
  private int CHILANY = 1;
  private boolean running;
  TweetStream tStream;
  
  public DataReader(ThreeLittleBirds proj4, String pathName){
 
    switch (streamChoice){
      case 1:{reader = createReader(pathName);
             break;}
      case 2:{tStream = new TweetStream(proj4, "stream.twitter.com", 80, "1/statuses/sample.json", "cs491proj4", "nogoodpass");
             tStream.go();
             break;}
      default: {}
    }
  }
  public void start() {
    running = true;
    super.start();
  }
  
  public void localData(){
    try {
      line = reader.readLine();
    } catch (IOException e) {
      e.printStackTrace();
      line = null;
    }
    if (line == null) {
      // Stop reading because of an error or file is empty
      noLoop();  
    } else {
       String[] pieces = split(line, TAB);
       if (pieces.length <2) running = false;
       else {addCount(pieces[0]);
       currentDateTime=pieces[1];  
       }
     }
    }

  
  public void liveData(){
    Date d = new Date();
    currentDateTime = d.toString();
  }
  
  public void run() {
    while (running){
      delay(2);
      switch (streamChoice){
        case 1:{localData();
               break;}
        case 2:{liveData();
               break;}
        default: {
        }
    }
  }
  }
 private void addCount(String cityName){
    if (cityName.equals(CHI)) chicagoCount++;
    else if (cityName.equals(NY)) newYorkCount++;
    else if (cityName.equals(LA)) losAngelesCount++;
    else {
    }
  }
  
 
  
  
}
